package com.study.algorithm.sort;

import java.util.Arrays;

public class SelectionSort {
    public static void sort(int[] nums) {
        int max;
        int maxIndex;
        for (int i = 0; i < nums.length; i++) {
            maxIndex = i;
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] < nums[maxIndex]) {
                    maxIndex = j;
                }
            }
            if (maxIndex != i) {
                max = nums[maxIndex];
                nums[maxIndex] = nums[i];
                nums[i] = max;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {1, 5, 8, 7, 1, 2, 5, 4, 66, 5, 84, 5, 110, 4, 5, 4};
        sort(nums);
        System.out.println("nums = " + Arrays.toString(nums));
    }
}
